// 318.最大单词长度乘积

package Leetcode;

public class Solution318 {
    public int maxProduct(String[] words) {
        int maxLength = 0;
        int[] mask = new int[words.length];

        // 第 i 位为 1 则表示第 i 个单词出现过
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            for (char c : word.toCharArray()) {
                mask[i] |= 1 << (c - 'a');
            }
        }

        for (int i = 0; i < words.length; i++) {
            for (int j = i + 1; j < words.length; j++) {
                if ((mask[i] & mask[j]) == 0)
                    maxLength = Math.max(maxLength, words[i].length() * words[j].length());
            }
        }

        return maxLength;
    }
}
